home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / ImageFXDevKit.lha / sdev / sas / examples / drawmodes / sharpen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  5.0 KB  |  216 lines

  1. /*
  2.  * A Drawing Mode for ImageFX 1.5
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8.  
  9. /**********************************************************************\
  10.  
  11.                                 Library Vectors
  12.  
  13. \**********************************************************************/
  14.  
  15. struct Buffer *buf;
  16. int last_y, brow;
  17. UBYTE *red, *grn, *blu;
  18.  
  19. /*
  20.  * Initialize before a series of PutColor or PutGrey's.  This is
  21.  * guaranteed to be called before any PutColor or PutGrey's.
  22.  *
  23.  */
  24. int __asm DM_PutInit (void)
  25. {
  26.    /*
  27.     * This mode requires an undo buffer...
  28.     *
  29.     */
  30.    buf = ObtainBuffer(3);
  31.    if (buf == NULL) return(0);
  32.  
  33.    last_y = -1;
  34.    brow = buf->BytesPerRow;
  35.  
  36.    return(1);
  37. }
  38.  
  39. /*
  40.  * Cleanup after a series of PutColor or PutGrey's.
  41.  *
  42.  */
  43. void __asm DM_PutCleanup (void)
  44. {
  45.    ReleaseBuffer(buf);
  46. }
  47.  
  48.  
  49. short __inline do_sharp (UBYTE *pix, short x, short y)
  50. {
  51.    short val;
  52.    short a1, a2, a3, a4;
  53.  
  54.    if (y > 0)
  55.       a1 = pix[x-brow];
  56.    else
  57.       a1 = pix[x];
  58.  
  59.    if (y < buf->Height-1)
  60.       a2 = pix[x+brow];
  61.    else
  62.       a2 = pix[x];
  63.  
  64.    if (x > 0)
  65.       a3 = pix[x-1];
  66.    else
  67.       a3 = pix[x];
  68.  
  69.    if (x < buf->Width-1)
  70.       a4 = pix[x+1];
  71.    else
  72.       a4 = pix[x];
  73.  
  74.    val = (pix[x] * 5) - a1 - a2 - a3 - a4;
  75.  
  76.    return(val);
  77. }
  78.  
  79. /*
  80.  * Write a color pixel.
  81.  *
  82.  */
  83. void __asm DM_PutColor (register __a0 short *destr,
  84.                         register __a1 short *destg,
  85.                         register __a2 short *destb,
  86. //                      register __d0 LONG oldr,
  87. //                      register __d1 LONG oldg,
  88. //                      register __d2 LONG oldb,
  89. //                      register __d3 LONG newr,
  90. //                      register __d4 LONG newg,
  91. //                      register __d5 LONG newb,
  92.                         register __d6 LONG x,
  93.                         register __d7 LONG y)
  94. {
  95.    y -= buf->ViewTop;
  96.    x -= buf->ViewLeft;
  97.  
  98.    if (y != last_y) {
  99.       if (!GetBufLines (buf, &red, &grn, &blu, y - 1, 3)) {
  100.          last_y = -1;
  101.          return;
  102.       }
  103.       red += brow; grn += brow; blu += brow;
  104.       last_y = y;
  105.    }
  106.  
  107.    *destr = do_sharp(red, x, y);
  108.    *destg = do_sharp(grn, x, y);
  109.    *destb = do_sharp(blu, x, y);
  110. }
  111.  
  112. /*
  113.  * Write a greyscale pixel.
  114.  *
  115.  */
  116. void __asm DM_PutGrey  (register __a0 short *destg,
  117.                         register __d0 LONG oldg,
  118.                         register __d1 LONG newg,
  119.                         register __d6 LONG x,
  120.                         register __d7 LONG y)
  121. {
  122.    y -= buf->ViewTop;
  123.    x -= buf->ViewLeft;
  124.  
  125.    if (y != last_y) {
  126.       if (!GetBufLines (buf, &red, &grn, &blu, y - 1, 3)) {
  127.          last_y = -1;
  128.          return;
  129.       }
  130.       red += brow; grn += brow; blu += brow;
  131.       last_y = y;
  132.    }
  133.  
  134.    *destg = do_sharp(red, x, y);
  135. }
  136.  
  137. /*
  138.  * Set state information for each point along a curve.  This is called
  139.  * at every point along a user-drawn curve (freehand draw, airbrush, etc.)
  140.  *
  141.  * You cannot rely on this being called after DM_PutInit(), or
  142.  * vice versa.
  143.  *
  144.  * x, y, and z will be -1 if the drawing tool in question is
  145.  * not a curve (eg. a box or something).
  146.  *
  147.  */
  148. void __asm DM_NewPoint (register __d0 int n,
  149.                         register __d1 int total,
  150.                         register __d2 int x,
  151.                         register __d3 int y,
  152.                         register __d4 int z)
  153. {
  154. }
  155.  
  156. /**********************************************************************\
  157.  
  158.                          Library Initialization Stuff
  159.  
  160. \**********************************************************************/
  161.  
  162. /*
  163.  * This is the table of all the functions that can be called in this
  164.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  165.  * for system use and MUST be specified in the order shown.  The actual
  166.  * functions are in the standard module startup code.
  167.  */
  168. ULONG FuncTable[] = {
  169.    /* These four MUST be present in this order */
  170.    (ULONG) LibOpen,
  171.    (ULONG) LibClose,
  172.    (ULONG) LibExpunge,
  173.    (ULONG) LibNull,
  174.  
  175.    /* Specific to the module */
  176.    (ULONG) DM_PutInit,
  177.    (ULONG) DM_PutCleanup,
  178.    (ULONG) DM_PutColor,
  179.    (ULONG) DM_PutGrey,
  180.    (ULONG) DM_NewPoint,
  181.  
  182.    /* End with -1L */
  183.    (ULONG) -1L
  184. };
  185.  
  186. /*
  187.  * These are used by the standard module startup code.
  188.  * LibraryName is the name of the library, and LibraryID is a short
  189.  * description of the library.  Both of these are largely irrelavent,
  190.  * but they are included just for completeness.
  191.  */
  192. UBYTE LibraryID[]    = "$VER: Sharpen Drawing Mode 1.04.17 (13.6.93)";
  193. UBYTE LibraryType    = NT_DRAWMODE;
  194.  
  195. /*
  196.  * This is called by the standard module startup code when Image Scan
  197.  * first opens the module.  Here we should fill in the NumGads,
  198.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  199.  * structure if necessary.
  200.  */
  201. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  202. {
  203.    return(TRUE);
  204. }
  205.  
  206. /*
  207.  * This is called by the standard module startup code when Image Scan
  208.  * closes the module.  It should cleanup anything allocated or obtained
  209.  * in the UserOpen() function.
  210.  */
  211. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  212. {
  213.    return(TRUE);
  214. }
  215.  
  216.